package zheezes.protocol.impl.wt;

import zheezes.util.AbstractSerial;
import zheezes.util.ByteUtil;

public class WtConAddr extends AbstractSerial {
	public static final int SIZE = 4;

	private byte[] addr = new byte[SIZE];

	public WtConAddr() {
	}

	public WtConAddr(byte[] addr) {
		System.arraycopy(addr, 0, this.addr, 0, this.addr.length);
	}
	
	public WtConAddr(String addr) {
		this(ByteUtil.stoa(addr.toCharArray()));
	}

	public WtConAddr(int addr) {
		this(ByteUtil.bltoc(addr));
	}

	public int size() {
		return SIZE;
	}

	public int setBytes(byte[] buf, int offset, int max) {
		int idx = offset;
		addr[0] = buf[idx++];
		addr[1] = buf[idx++];
		addr[3] = buf[idx++];
		addr[2] = buf[idx++];

		return idx - offset;
	}

	public int getBytes(byte[] buf, int offset) {
		int idx = offset;
		buf[idx++] = this.addr[0];
		buf[idx++] = this.addr[1];
		buf[idx++] = this.addr[3];
		buf[idx++] = this.addr[2];

		return idx - offset;
	}
}
